<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/5/10
 * Time: 16:51
 */
namespace MyClass\Admin;
use Illuminate\Support\Facades\DB;

class ArticleClassBase
{
    private $class_id;

    public static function sClass()
    {
        $data=DB::table("article_class")->get();

        if($data)
        {
            return $data;
        }
        else
        {
            return false;
        }
    }
    public static function sClassName($class_id){
        $data=DB::table("article_class")->where("class_id","=",$class_id)->get();
        return $data;
    }
    public static function _sClass()
    {
        $data["inputData"]=DB::table("article_class")->paginate(6);
        $data["nowPage"]=$data["inputData"]->currentPage();
        $data["allPage"]=$data["inputData"]->lastPage();
        if($data)
        {
            return $data;
        }
        else
        {
            return false;
        }
    }
    public static function aClass($data)
    {
        $data["class_create_time"]=date("Y-m-d H:i:s");
        $data["class_update_time"]=date("Y-m-d H:i:s");
        $res=DB::table("article_class")->insert($data);
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public static function sClassId($class_name)
    {
        $id=DB::table("article_class")
            ->where("class_name","=",$class_name)
            ->pluck("class_id");
        if($id)
        {
            return  $id[0];
        }
        else
        {
            return false;
        }
    }

    public function __construct($class_id)
    {
        $this->class_id=$class_id;
    }
    public function uClass($data)
    {
        $res=DB::table("article_class")
            ->where("class_id","=",$this->class_id)
            ->update($data);
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public function dClass()
    {
        $res=DB::table("article_class")
            ->where("class_id","=",$this->class_id)
            ->delete();
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}